﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PureMVC.Patterns;
using PureMVC.Interfaces;
using GameEngine.Clients.Silverlight.View;
using GameEngine.View;
using SilverlightShowCase.View.Components;
using GameEditor;
using System.IO;
using GameEngine.Model.Data;

namespace SilverlightShowCase.Commands
{
    public class Page_Main_In_Command : SimpleCommand
    {
        override public void Execute(INotification notification)
        {
            Application app = notification.Body as Application;
            MenuMediator<string, MainMenu> mediator = new MenuMediator<string, MainMenu>(
                MyFacade.MyMainMenuMediatorName, 
                new MainMenu(), 
                MyFacade.MY_PAGE_MAIN_OUT_COMMAND);
            MyFacade.Instance.RegisterMediator(mediator);
            MyFacade.Instance.Start(app, true, mediator.ViewComponent);
        }
    }

    public class Page_Main_Out_Command : SimpleCommand
    {
        override public void Execute(INotification notification)
        {
            MyFacade.Instance.RemoveMediator(MyFacade.MyMainMenuMediatorName);
            switch (notification.Body as string) {
                case MainMenu.PLAYBUTTON:
                    OpenFileDialog ofd = new OpenFileDialog();
                    if (ofd.ShowDialog().Value)
                    {
                        TextReader w = new StreamReader(ofd.File.OpenRead());
                        string gameSerialized = w.ReadToEnd();
                        w.Close();
                        var game = new GameVO<int>();
                        game.DeSerialize(gameSerialized);
                        SendNotification(MyFacade.MY_PAGE_PLAY_IN_COMMAND, game);
                    }
                    break;
                case MainMenu.EDITORBUTTON:
                    MyFacade.Instance.SendNotification(MyFacade.MY_PAGE_GAMESEDITOR_IN_COMMAND);
                    break;
                case MainMenu.EXITBUTTON:
                    break;
             }
        }
    }
}
